<template>
  <view>
    <!-- 页面顶部搜索组件 -->
    <view class="search-box">
      <my-search @click='gotoSearch'></my-search>
    </view>
    <!-- 轮播图区域 -->
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
      <swiper-item v-for="(item,i) in swiperList" :key="i">
        <navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
          <image :src="item.image_src"></image>
        </navigator>
      </swiper-item>
    </swiper>
    <!-- 分类导航区域 -->
    <view class="nav-list">
      <view class="nav-item" v-for="(item,i) in navList" :key="i">
        <image :src="item.image_src" @click="navClickEvent(item)"></image>
      </view>
    </view>
    <!-- 楼层区域 -->
    <view class="floor-list" v-for="(item,i) in floorList" :key='i'>
      <!-- 楼层标题部分 -->
      <view class="floor-top">
        <image :src="item.floor_title.image_src"></image>
      </view>
      <!-- 楼层图片导航部分 -->
      <view class="floor-bottom">
        <!-- 楼层左侧图片导航 -->
        <navigator class="fl"  :url="item.product_list[0].url">
          <image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
        </navigator>
        <!-- 楼层右侧图片导航 -->
        <view class="fr">
          <navigator class="right_img_item" v-for="(item2,i2) in item.product_list" :key="i2" v-if="i2!==0" :url="item2.url">
            <image :src="item2.image_src" :style="{width:item2.image_width+'rpx'}" mode="widthFix"></image>
          </navigator>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import badgeMix from '../../mixins/tabbar-badge.js'
  export default {
    mixins:[badgeMix],
    data() {
      return {
        swiperList:[],
        navList:[],
        floorList:[],
      };
    },
    methods:{
      // 获取轮播图数据
      async getSwiperList(){
        const {data:res}=await uni.$http.get('/api/public/v1/home/swiperdata')
        if(res.meta.status!==200)return uni.$showMsg()
        this.swiperList=res.message
        // console.log(this.swiperList=res.message)
      },
      // 获取导航列表数据
      async getNavList(){
        const {data:res}=await uni.$http.get('/api/public/v1/home/catitems')
        if(res.meta.status!==200)return uni.$showMsg()
        this.navList=res.message
        // console.log(res)
      },
      // 获取楼层数据
      async getFloorList(){
        const {data:res}=await uni.$http.get('/api/public/v1/home/floordata')
        if(res.meta.status!==200)return uni.$showMsg()
        res.message.forEach(floor=>{
          floor.product_list.forEach(prod=>{
            prod.url='/subpkg/goods_list/goods_list?'+prod.navigator_url.split('?')[1]
          })
        })
        this.floorList=res.message
        // console.log(res)
      },
      // 导航栏点击事件
      navClickEvent(val){
        switch(val.name){
          case "分类":
            uni.switchTab({
              url:"/pages/cate/cate"
            })
            break;
          default:
            uni.$showMsg(val.name)
            break;
        }
        // console.log(val)
      },
      // 搜索组件点击事件
      gotoSearch(){
        uni.navigateTo({
          url:"../../subpkg/search/search"
        })
      }
    },
    onLoad(){
      this.getSwiperList()
      this.getNavList()
      this.getFloorList()
    }
  }
</script>

<style lang="scss">
// 页面顶部搜索组件
.search-box{
  position:sticky;
  top: 0;
  z-index: 999;
}
  // 轮播图区域
swiper{
  height: 300rpx;
  .swiper-item,
  image{
    height: 100%;
    width: 100%;
  }
}
// 导航列表区域
.nav-list{
  height: 150rpx;
  padding: 8rpx;
  .nav-item{
    display: inline-block;
    height: 100%;
    width: 25%;
    padding: 0 24rpx;
    box-sizing: border-box;
    image{
      height: 100%;
      width: 100%;
    }
  }
}
// 各楼层区域
.floor-list{
  margin-top: 10rpx;
  box-sizing: border-box;
  .floor-top>image{
    height: 60rpx;
  }
  .floor-bottom{
    display: flex;
    justify-content: space-around;
    box-sizing: border-box;
    margin-left: 10rpx;
    .fr{
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
      margin-left: 10rpx;
    }
  }
}
</style>
